package study.elasticsearch.controller;

import factory.SourceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.ReceiveVo;
import study.elasticsearch.repository.BbsRepository;

@RestController
public class BbsController {

    @Autowired
    BbsRepository userRepository;

    /**
     * 创建索引
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/index")
    public String index(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .setSource(vo.getContent()).build();
        return userRepository.index(info);
    }

    /**
     * 获取
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/get")
    public String get(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return userRepository.get(info);
    }

    /**
     * 存在
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/exist")
    public boolean exist(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return userRepository.exist(info);
    }

    /**
     * 删除
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/delete")
    public String delete(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return userRepository.delete(info);
    }

    /**
     * 修改
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/update")
    public String update(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .setSource(vo.getContent()).build();
        return userRepository.update(info);
    }

    /**
     * 批量操作
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/bulk")
    public Integer bulk(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return userRepository.bulk(info);
    }





}
